package edu.webtek.clouddata;

import org.jdom2.Element;

public class Item {
	final private int itemID, itemPrice, itemStock;
	final private String itemName, itemURL, itemDescription;
	public int getItemID() {
		return itemID;
	}
	public int getItemPrice() {
		return itemPrice;
	}
	public int getItemStock() {
		return itemStock;
	}
	public String getItemName() {
		return itemName;
	}
	public String getItemURL() {
		return itemURL;
	}
	public String getItemDescription() {
		return itemDescription;
	}
	
	public Item(Element item) {
		int itemID = -1, itemPrice = -1, itemStock = -1;
		String itemName = "NULL", itemURL = "NULL", itemDescription = "NULL";
		
		for(Element attr : item.getChildren()){
			String data = attr.getText();
			switch(attr.getName()){
			case "itemID":
				itemID = Integer.parseInt(data);
				break;
			case "itemPrice":
				itemPrice = Integer.parseInt(data);
				break;
			case "itemStock":
				itemStock = Integer.parseInt(data);
				break;
			case "itemName":
				itemName = data;
				break;
			case "itemURL":
				itemURL = data;
				break;
			case "itemDescription":
				itemDescription = data;
				break;
			}
		}
		
		this.itemName  		 = itemName;
		this.itemURL  		 = itemURL;
		this.itemDescription = itemDescription;
		this.itemID 		 = itemID;
		this.itemPrice 		 = itemPrice;
		this.itemStock 		 = itemStock;
	}
	@Override
	public String toString() {
		return "Item [itemID=" + itemID + ", itemPrice=" + itemPrice
				+ ", itemStock=" + itemStock + ", itemName=" + itemName
				+ ", itemURL=" + itemURL + ", itemDescription="
				+ itemDescription + "]";
	}
	
	
}
